package com.example.controller;

import com.example.DTO.LogInDTO;
import com.example.pojo.User;
import com.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

//登录页面
@RestController
@RequestMapping("/user")
public class LogInController {
    @Autowired
    private UserService userService;
    @PostMapping("/login")
    public Map<String, Object> login(@RequestBody LogInDTO loginDTO) {
        Map<String, Object> result = new HashMap<>();

        try {
            User user = userService.login(loginDTO);

            result.put("success", true);
            result.put("message", "登录成功");
            result.put("data", user);
        } catch (Exception e) {
            result.put("success", false);
            result.put("message", e.getMessage());
            result.put("data", null);
        }

        return result;
    }
}
